var pai_patterns = [
  { name: '平胡', times: 1, tag: 1 },
  { name: '大对子', times: 2, tag: 1 },
  // { name: '门清', times: 2, optinal: true, huOnly: true, tag: 3 },
  { name: '清一色', times: 4, tag: 1 },
  { name: '七对', times: 4, tag: 1 },
  { name: '幺九', times: 4, optinal: true, tag: 3 },
  { name: '断幺九', times: 2, optinal: true, tag: 3 },
  { name: '将对', times: 8, optinal: true, tag: 3 },
  { name: '龙七对', times: 8, tag: 1 },
  { name: '天地胡', times: 32, optinal: true, huOnly: true, tag: 3 },
  { name: '海底捞月', times: 2, optinal: true, huOnly: true, tag: 3 },
  { name: '带根', times: 2, tag: 2 },
  { name: '加番', times: 2, tag: 2 },
];

var hu_patterns = [
  { name: '自摸', times: 1, tag: 1 },   // 为了做自摸加番，设成 1
  { name: '杠上花', times: 2, tag: 1 },
  { name: '杠上炮', times: 2, tag: 1 }
];

var gang_patterns = [
  { name: '暗杠', times: 2 },
  { name: '补杠', times: 2 },
  { name: '直杠', times: 2 },
]

exports.hu_patterns = hu_patterns;
exports.gang_patterns = gang_patterns;

exports.calculateHuTimes = function (names) {
  var times = 1;
  names.forEach(function (name) {
    times *= pai_patterns.concat(hu_patterns).find( e => e.name == name ).times;
  })
  return times;
}

exports.calculateGangTimes = function (name) {
  return gang_patterns.find(e => e.name == name).times;
}

exports.allPatterns = function () {
  var patterns = {};

  patterns['胡'] = pai_patterns.concat(hu_patterns).filter(e => !e.optinal).map(e => e.name);
  patterns['杠'] = gang_patterns.map(e => e.name);
  patterns['查叫'] = pai_patterns.filter(e => !e.optinal).map(e => e.name);
  patterns['胡可选'] = pai_patterns.filter(e => e.optinal).map(e => e.name);
  patterns['查叫可选'] = pai_patterns.filter(e => e.optinal && !e.huOnly).map(e => e.name);
  patterns['tags'] = [].concat(pai_patterns, hu_patterns, gang_patterns).map(e => ({ name: e.name, tag: e.tag }))

  return patterns;
}
